<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-CH">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/niko/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/niko/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/niko/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/niko/favicon.ico?v=5.1.1" />






<meta name="description" content="2.初识Weexdemo-Example了解Weex源码结构，修改example其实，写一个简单的带有样式的界面还是挺简单的。接下来就是要学习官方给的example示例，看一下官方的目录结构以及示例代码，开发过程中遇到的不明白的问题其实很多都能在官方demo里找到答案。          1. 下载Weex源码weexGithub这里可以用 git clone 或者直接download $ git">
<meta property="og:type" content="article">
<meta property="og:title" content="NikoBlog">
<meta property="og:url" content="http://git.oschina.net/280772270/niko/2017/06/20/2.初识Weexdemo-Example/index.html">
<meta property="og:site_name" content="NikoBlog">
<meta property="og:description" content="2.初识Weexdemo-Example了解Weex源码结构，修改example其实，写一个简单的带有样式的界面还是挺简单的。接下来就是要学习官方给的example示例，看一下官方的目录结构以及示例代码，开发过程中遇到的不明白的问题其实很多都能在官方demo里找到答案。          1. 下载Weex源码weexGithub这里可以用 git clone 或者直接download $ git">
<meta property="og:image" content="http://git.oschina.net/280772270/niko/2017/06/20/2.初识Weexdemo-Example/resources/EAFF24F8C94E94BDA4EF1111E6B93CA1.png">
<meta property="og:image" content="http://git.oschina.net/280772270/niko/2017/06/20/2.初识Weexdemo-Example/resources/2921B70E8426AEF20538254492591280.png">
<meta property="og:image" content="http://gtms04.alicdn.com/tps/i4/TB1wCcqMpXXXXakXpXX3G7tGXXX-34-44.png">
<meta property="og:image" content="http://img1.tbcdn.cn/L1/461/1/5470b677a2f2eaaecf412cc55eeae062dbc275f9">
<meta property="og:image" content="http://git.oschina.net/280772270/niko/2017/06/20/2.初识Weexdemo-Example/resources/94C9F54632F28B576381F1816C1C57ED.png">
<meta property="og:image" content="http://git.oschina.net/280772270/niko/2017/06/20/2.初识Weexdemo-Example/resources/F7EFC1DCBD17406E556FF19833D07D98.png">
<meta property="og:image" content="http://git.oschina.net/280772270/niko/2017/06/20/2.初识Weexdemo-Example/resources/EE1AFFDA3B33D4DB78D5600879CBCC25.png">
<meta property="og:updated_time" content="2017-06-20T02:27:12.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="NikoBlog">
<meta name="twitter:description" content="2.初识Weexdemo-Example了解Weex源码结构，修改example其实，写一个简单的带有样式的界面还是挺简单的。接下来就是要学习官方给的example示例，看一下官方的目录结构以及示例代码，开发过程中遇到的不明白的问题其实很多都能在官方demo里找到答案。          1. 下载Weex源码weexGithub这里可以用 git clone 或者直接download $ git">
<meta name="twitter:image" content="http://git.oschina.net/280772270/niko/2017/06/20/2.初识Weexdemo-Example/resources/EAFF24F8C94E94BDA4EF1111E6B93CA1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/niko/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://git.oschina.net/280772270/niko/2017/06/20/2.初识Weexdemo-Example/"/>





  <title> | NikoBlog</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CH">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/niko/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">NikoBlog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">TecBlog</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/niko/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Startseite
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/niko/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archiv
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/niko/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://git.oschina.net/280772270/niko/niko/2017/06/20/2.初识Weexdemo-Example/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Yifei's">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/niko/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="NikoBlog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline"></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Veröffentlicht am</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-06-20T10:27:12+08:00">
                2017-06-20
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="2-初识Weexdemo-Example"><a href="#2-初识Weexdemo-Example" class="headerlink" title="2.初识Weexdemo-Example"></a>2.初识Weexdemo-Example</h1><h2 id="了解Weex源码结构，修改example"><a href="#了解Weex源码结构，修改example" class="headerlink" title="了解Weex源码结构，修改example"></a>了解Weex源码结构，修改example</h2><p>其实，写一个简单的带有样式的界面还是挺简单的。接下来就是要学习官方给的example示例，看一下官方的目录结构以及示例代码，开发过程中遇到的不明白的问题其实很多都能在官方demo里找到答案。         </p>
<h2 id="1-下载Weex源码"><a href="#1-下载Weex源码" class="headerlink" title="1. 下载Weex源码"></a>1. 下载Weex源码</h2><p><a href="https://github.com/alibaba/weex" target="_blank" rel="external">weexGithub</a><br>这里可以用 <strong>git clone</strong> 或者直接download</p>
<pre><code>$ git clone https://github.com/alibaba/weex.git    
</code></pre><h2 id="2-了解源码结构"><a href="#2-了解源码结构" class="headerlink" title="2.了解源码结构"></a>2.了解源码结构</h2><p>代码下载完成了，先看一下源码的目录结构。  </p>
<p><img src="resources/EAFF24F8C94E94BDA4EF1111E6B93CA1.png" alt="QQ20160926-1.png"></p>
<p>有几个比较重要的目录和文件：  </p>
<ul>
<li>package.json :    node_modules依赖，更重要的是里面包含了npm run xxx 等快捷命令。这里我们可以把它配置化，例如package.json文件中的：        </li>
</ul>
<p><img src="resources/2921B70E8426AEF20538254492591280.png" alt="QQ20160926-2.png"></p>
<ul>
<li><p>start文件: 启动程序文件，<strong>相当于Windows下面的*.bat脚本文件</strong>：      </p>
<pre><code>#called by native   
THIS_DIR=$(dirname &quot;$0&quot;)
pushd &quot;$THIS_DIR&quot;

npm run build:native
npm run build:browser
npm run serve &amp;
npm run dev:examples

popd
</code></pre></li>
</ul>
<p>其中npm run就是执行package.json中的定义好的脚本别名。          </p>
<ul>
<li>examples: 示例Demo      </li>
<li>android/ios/html： 各平台代码   </li>
<li>build：打包各平台的脚本，配置在package.json中。         </li>
</ul>
<h2 id="3-运行Weex"><a href="#3-运行Weex" class="headerlink" title="3.运行Weex"></a>3.运行Weex</h2><p>下面是weex github仓库README.md，按照下面步骤即可跑起来。     </p>
<h3 id="Android"><a href="#Android" class="headerlink" title="Android"></a>Android</h3><ol>
<li>Prerequisites<ol>
<li>Install <a href="http://nodejs.org/" target="_blank" rel="external">Node.js</a> 4.0+</li>
<li>Under project root <ol>
<li><code>npm install</code>, install project </li>
<li><code>./start</code></li>
</ol>
</li>
<li>Install <a href="http://developer.android.com/training/basics/firstapp/index.html" target="_blank" rel="external">Android Environment</a></li>
</ol>
</li>
<li>Run playground, In Android Studio<ol>
<li>Open <code>android/playground</code></li>
<li>In <code>app/java/com.alibaba.weex/IndexActivity</code>, modify <code>CURRENT_IP</code> to your local IP</li>
<li>Click <img src="http://gtms04.alicdn.com/tps/i4/TB1wCcqMpXXXXakXpXX3G7tGXXX-34-44.png" height="16"> (<code>Run</code> button)</li>
</ol>
</li>
<li><a href="./examples/README.md#add-an-example">Add an example</a></li>
</ol>
<h4 id="Runtime"><a href="#Runtime" class="headerlink" title="Runtime"></a>Runtime</h4><p>On Android Platform , Weex code is executed in <a href="https://github.com/alibaba/weex_v8core" target="_blank" rel="external">weex_v8core</a> which is based on Google V8 JavaScript engine.</p>
<h3 id="iOS"><a href="#iOS" class="headerlink" title="iOS"></a>iOS</h3><ol>
<li>Prerequisites<ol>
<li>Install <a href="http://nodejs.org/" target="_blank" rel="external">Node.js</a> 4.0+</li>
<li>Under project root <ol>
<li><code>npm install</code>, install project </li>
<li><code>./start</code></li>
</ol>
</li>
<li>Install <a href="https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppStoreDistributionTutorial/Setup/Setup.html" target="_blank" rel="external">iOS Environment</a></li>
<li>Install <a href="https://guides.cocoapods.org/using/getting-started.html" target="_blank" rel="external">CocoaPods</a></li>
</ol>
</li>
<li>Run playground<ol>
<li><code>cd ios/playground</code></li>
<li><code>pod install</code></li>
<li>Open <code>WeexDemo.xcworkspace</code> in Xcode</li>
<li>Click <img src="http://img1.tbcdn.cn/L1/461/1/5470b677a2f2eaaecf412cc55eeae062dbc275f9" height="16"> (<code>Run</code> button) or use default shortcut <code>cmd + r</code> in Xcode</li>
<li>If you want to run the demo on your device. In <code>DemoDefine.h</code>(you can search this file by Xcode default shortcut <code>cmd + shift + o</code>), modify <code>CURRENT_IP</code> to your local IP</li>
</ol>
</li>
</ol>
<p>运行的结果，如下图：             </p>
<p><img src="resources/94C9F54632F28B576381F1816C1C57ED.png" alt="002\_3.png"></p>
<p>但是，我们也希望在浏览器中看到效果，那么输入如下网站也可：     </p>
<pre><code>http://127.0.0.1:12580        
</code></pre><h2 id="4-修改example"><a href="#4-修改example" class="headerlink" title="4.修改example"></a>4.修改example</h2><p><img src="resources/F7EFC1DCBD17406E556FF19833D07D98.png" alt="002\_4.png"></p>
<p>其中index.we是入口文件。因此可以在example中增加一个文件。然后在index.we中增加一个name和title。          </p>
<p><img src="resources/EE1AFFDA3B33D4DB78D5600879CBCC25.png" alt="002\_5.png"></p>
<p>刷新即可查看效果。      </p>
<h2 id="5-如何学习"><a href="#5-如何学习" class="headerlink" title="5.如何学习"></a>5.如何学习</h2><p>到这里就可以调试单独的文件了，查看各种效果以及测试语法，开发过程中的问题还是建议阅读源码</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/niko/2017/06/20/3.初始化工程/" rel="next" title="">
                <i class="fa fa-chevron-left"></i> 
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/niko/2017/06/20/1.HellowWeex/" rel="prev" title="">
                 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Inhaltsverzeichnis
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Übersicht
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/niko/images/avatar.gif"
               alt="Yifei's" />
          <p class="site-author-name" itemprop="name">Yifei's</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/niko/archives/">
                <span class="site-state-item-count">7</span>
                <span class="site-state-item-name">Artikel</span>
              </a>
            </div>
          

          

          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#2-初识Weexdemo-Example"><span class="nav-number">1.</span> <span class="nav-text">2.初识Weexdemo-Example</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#了解Weex源码结构，修改example"><span class="nav-number">1.1.</span> <span class="nav-text">了解Weex源码结构，修改example</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-下载Weex源码"><span class="nav-number">1.2.</span> <span class="nav-text">1. 下载Weex源码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-了解源码结构"><span class="nav-number">1.3.</span> <span class="nav-text">2.了解源码结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-运行Weex"><span class="nav-number">1.4.</span> <span class="nav-text">3.运行Weex</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Android"><span class="nav-number">1.4.1.</span> <span class="nav-text">Android</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Runtime"><span class="nav-number">1.4.1.1.</span> <span class="nav-text">Runtime</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#iOS"><span class="nav-number">1.4.2.</span> <span class="nav-text">iOS</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-修改example"><span class="nav-number">1.5.</span> <span class="nav-text">4.修改example</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-如何学习"><span class="nav-number">1.6.</span> <span class="nav-text">5.如何学习</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Yifei's</span>
</div>


<div class="powered-by">
  Erstellt mit  <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/niko/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/niko/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/niko/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/niko/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/niko/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/niko/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/niko/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/niko/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/niko/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/niko/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/niko/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
